new Vue({
  el: '#app',
  data() {
    return {
      form: {
        Applicable_Type: "",
        Warehouse_Type: "",
        page: 1,			//页数
        limit: 10			//每页数据条数
      },
      total: 0,
      tableData: [],		//表格数据
    }
  },
  mounted() {
    this.getList(this.form)
  },
  methods: {
    onSerach() {			//查询方法
      this.form.page = 1;
      this.getList(this.form)
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    handleChildren(row) {
      const _this = this
      $.ajax({
        url: `${DomainName}/getWarehouseInventoryID?token=${$.cookie('token')}`,
        type: 'POST',
        data: {
          Warehouse_SerialNumber: row.Applicable_Type == '0' ? row.Warehouse_SerialNumber : row.Parent_Warehouse_SerialNumber
        },
        success: function (res) {
          console.log(row);
          row.Children.warehouse_inventory = res
        },
        dataType: "json"
      });
    },
    getList(data) {     //换页方法
      const _this = this
      $.ajax({
        type: 'POST',
        url: `${DomainName}/getWarehouseAllAction?token=${$.cookie('token')}`,
        data,
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (Result) {
          if (Result.Status == 'success') {
            _this.tableData = Result.tableData
            _this.total = parseInt(Result.limit)
            console.log(_this.tableData);
          }
        },
        dataType: "json"
      });
    },
    addEnterprise() {
      window.location.href = './Add.html'
    },
    editMember(Store_SerialNumber) {
      sessionStorage.setItem("Store_SerialNumber", Store_SerialNumber)
      window.location.href = './Edit.html?Store_SerialNumber=' + Store_SerialNumber
    },
    deletMember(Store_SerialNumber) {
      this.$confirm('此操作将删除该系列, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.delete(Store_SerialNumber);
        this.getList1();
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    delete(Store_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/StoreInfo_Original',
        type: 'GET',
        async: false,
        data: { action: "jQueryAjax" },
        success: function (res) {
          console.log(res);
          for (let i = 0; i < res.length; i++) {
            if (res[i].Store_SerialNumber == Store_SerialNumber) {
              res[i].Row_Status = '1'
              _this.detel = res[i];
            }
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
      let data = { Data: JSON.stringify({ Modify: { store_info: [_this.detel] } }) };
      $.ajax({
        url: DomainName + '/GoodsFileEdit',
        type: 'POST',
        async: false,
        data: data,
        error: function () {
          _this.$message.error("删除失败，请稍后再试")
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    GoWareDetail(row){
      sessionStorage.setItem('WareDetail',JSON.stringify(row))
      window.location.href = './WareDetail.html?Warehouse_SerialNumber'
    }
  },
})